package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"video/models"
	"video/util"
)

type UserControllers struct {
	beego.Controller
}

func (c *UserControllers) Login() {
	username := c.GetString("username")
	password := c.GetString("password")
	var user models.User
	err := models.DB.Where("username=?", username).First(&user).Error
	if err != nil {
		c.Data["json"] = Json{
			Code: 500,
			Msg:  "用户名错误",
			Data: nil,
		}
		c.ServeJSON()
		return
	}
	if user.Password == util.MD5Encrypt(password) {
		c.Data["json"] = Json{
			Code: 200,
			Msg:  "登录成功",
			Data: nil,
		}
		c.ServeJSON()
		return
	} else {
		c.Data["json"] = Json{
			Code: 500,
			Msg:  "密码错误",
			Data: nil,
		}
		c.ServeJSON()
		return
	}
}
